/* 
 * Block Cache Layer
 * 
 * cache.h
 *
 * Interface to a cache of blocks.
 * 
 */

#ifndef _CACHE_H_
#define _CACHE_H_

#ifdef USE_LOG_SOFS
	#define BLOCK_READ(log,register_no,block)			logrw_read(log,register_no,block)
	#define BLOCK_WRITE(log,register_no,block)			logrw_write(log,register_no,block)
	#include "../include/logrw.h"
#else // use simple block allocator
	#define BLOCK_READ(bks,block_no,block)			block_read(bks,block_no,block)
	#define BLOCK_WRITE(bks,block_no,block)			block_write(bks,block_no,block)
	#include "../include/block.h"
#endif

#include "../include/fs.h"

/*
 * cache_init: initialize block/register cache
 * - bks: the blocks/registers instance to be cached
 *
 */
void cache_init(DISK_TYPE* allocator);

/*
 * cache_read: read a whole block/register
 * - no: the number of the block/register to read
 * - block: the buffer were to copy the block/register 
 *   returns: 0 if sucessful, -1 if not
 */
int cache_read( unsigned no, char* block);


/*
 * cache_write: write a whole block/register
 * - no: the number of the block/register to write
 * - block: the data with the data to write
 *   returns: 0 if sucessful, -1 if not
 */
int cache_write( unsigned no, char* block);


/*
 * cache_block_flush: forces flush of any dirty cache block/register
 */
void cache_flush();


/*
 * cache_dump_stats: display statics of the cache
 */
void cache_dump_stats();
#endif
